# import time
#
# import requests
# class Test:
#     # 魔法方法，用于初始化对象
#     def __init__(self,data):
#         self.url = "http://222.134.245.144:17000/chuanganqi/"
#         # self.cumulative_flow = 0
#         # self.instantaneous_flows = []
#         self.single_pump_threshold = 100  # 单泵压差阈值，单位假设为psi
#         self.double_pump_threshold = 200  # 双泵压差阈值，单位假设为psi
#         self.zhufubeng=[]
#         self.data = data
#     # 气瓶处理逻辑的主方法
#     def Xnq(self, url, device_name):
#         try:
#             # 发送GET请求
#             response = requests.get(url)
#             # 检查请求是否成功
#             if response.status_code == 200:
#                 # 解析数据
#                 data = response.json()
#                 # 获取结果部分
#                 results = data.get("results",[])
#                 # 如果没有结果，直接返回空列表
#                 if not results:
#                     print(f"API {url} 返回结果为空")
#                     return []
#                 # 取最新的一条数据
#                 latest_result = results[-1]
#                 device_id = latest_result.get("id")
#                 device_data = latest_result.get("data", [])
#
#                 # 检查 device_data 是否是列表
#                 if not isinstance(device_data, list):
#                     print(f"设备 {device_name} 的数据格式错误，设备ID: {device_id}")
#                     return []
#
#                 # 输出设备的ID和数据
#                 print(f"设备 {device_name}的ID:{device_id}")
#                 print(f"设备 {device_name} 的数据: {', '.join(map(str, device_data))}")
#
#                 # 设置预设值和容差范围
#                 high_set_value = 18  # 等高点预设温度值
#                 mid_set_value = 18  # 等中点预设温度值
#                 tolerance = 5  # 温度差异容差范围
#
#                 # 检查数据是否足够（每个设备有20个温度值）
#                 if len(device_data) < 20:
#                     print(f"设备 {device_name}的ID:{device_id} 热成像传感器损坏")
#                     return []
#
#                 # 将前10个温度值作为等高点温度，后10个温度值作为等中点温度
#                 high_points = device_data[:10]  # 前10个值为等高点温度
#                 mid_points = device_data[10:20]  # 后10个值为等中点温度
#
#                 # 设置一个开关，全部正常就输出正常
#                 all_normal = True
#
#                 # 遍历检查每个气瓶的温度
#                 for i in range(10):
#                     high_temp = high_points[i]
#                     mid_temp = mid_points[i]
#
#                     # 判断等高点温度差异
#                     if abs(high_temp - high_set_value) > tolerance:
#                         print(
#                             f"设备 {device_name}的ID:{device_id} 气瓶 {i + 1} 胶囊损坏（等高点温度异常：{high_temp}）")
#                         all_normal = False
#                         continue  # 等高点异常直接跳过
#
#                     # 如果等高点正常，再判断等中点温度差异
#                     if abs(mid_temp - mid_set_value) > tolerance:
#                         print(f"设备 {device_name}的ID:{device_id} 气瓶 {i + 1} 气体泄漏（等中点温度异常：{mid_temp}）")
#                         all_normal = False
#
#                 # 如果所有气瓶都正常，输出提示信息
#                 if all_normal:
#                     print(f"设备 {device_name}的ID:{device_id} 所有气瓶检查完成！正常")
#                 return [latest_result]
#             else:
#                 print(f"请求失败，状态码: {response.status_code}")
#                 return []
#         except requests.RequestException as e:
#             print(f"请求发生错误: {e}")
#             return []
#     # 气瓶一
#     def XnqX1(self):
#         # 模拟从超声流量计获取流量数据
#         url = self.url + "Csxnq01DeviceModel/"
#         response = requests.get(url)
#         if response.status_code == 200:
#             data = response.json()
#             results = data.get("results", [])
#             latest_result = results[-1]
#             xnqid=latest_result.get("id")
#             xnqdata=latest_result.get("data")
#             if xnqdata!=0:
#                 print(f"蓄能器1阀门泄露 瞬时流量为:{xnqdata}")
#             else:
#                 print("蓄能器1阀门泄露未发现泄露")
#
#     # 气瓶二
#     def XnqX2(self):
#         # 模拟从超声流量计获取流量数据
#         url = self.url + "Csxnq02DeviceModel/"
#         response = requests.get(url)
#         if response.status_code == 200:
#             data = response.json()
#             results = data.get("results", [])
#             latest_result = results[-1]
#             xnqid = latest_result.get("id")
#             xnqdata = latest_result.get("data")
#             if xnqdata != 0:
#                 print(f"蓄能器2阀门泄露 瞬时流量为:{xnqdata}")
#             else:
#                 print("蓄能器2阀门泄露未发现泄露")
#     # 1号气瓶
#     def Qip1(self):
#         url1 = self.url + "Rcx01DeviceModel/"
#         url2 = self.url + "Rcx02DeviceModel/"
#         self.Xnq(url1, "1号1-10设备")
#         self.Xnq(url2, "1号11-20设备")
#         print(f"1号设备检查完成")
#     # 2号气瓶
#     def Qip2(self):
#         url1 = self.url + "Rcx03DeviceModel/"
#         url2 = self.url + "Rcx04DeviceModel/"
#         self.Xnq(url1, "2号1-10设备")
#         self.Xnq(url2, "2号11-20设备")
#         print(f"2号设备检查完成")
#     # 判断几号#是主泵
#     def bengdata(self):
#         url = self.url + "FieldConfigModel/"
#         response = requests.get(url)
#         if response.status_code == 200:
#             data = response.json()
#             results = data.get("results", [])
#             if results and isinstance(results, list):
#                 pump_names = []  # 用于存储标准化的泵名称
#                 for result in results:
#                     zhufubeng_data = result.get("zhufubeng", [])
#                     for pump_info in zhufubeng_data:
#                         pump_type = pump_info["pump"]
#                         pump_name = pump_info["name"]
#                         # 统一键格式，去除多余描述，使用"泵名称-类型"格式
#                         if pump_type == "主泵":
#                             pump_names.append(f"{pump_name}-主泵")
#                         elif pump_type == "副泵":
#                             pump_names.append(f"{pump_name}-副泵")
#                 if len(pump_names) >= 2:
#                     return pump_names[0], pump_names[1]  # 返回标准化的两个泵名称
#                 else:
#                     return "未知主泵", "未知副泵"  # 处理数据不足的情况
#             else:
#                 print("未找到有效的 zhufubeng 数据")
#                 return "未定义主泵", "未定义副泵"
#         else:
#             print(f"请求失败，状态码: {response.status_code}")
#             return "请求失败主泵", "请求失败副泵"
#     # 模拟获取泵运行状态（True表示运行，False表示停止）
#     def get_status(self):
#         url = "http://222.134.245.144:17000//chuanganqi/BopPanelModel/"
#         response = requests.get(url)
#         if response.status_code == 200:
#             data = response.json()
#             results = data.get("results", [])
#             if not results:
#                 return {}
#             latest_result = results[0]
#             device_id1 = latest_result.get("dian_beng_1").get("deng")
#             device_id2 = latest_result.get("dian_beng_2").get("deng")
#             pump_main, pump_f = self.bengdata()  # 获取标准化的泵名称
#             # 使用统一的键格式，与振动数据保持一致
#             if pump_main=="1#pump-主泵的灯":
#                 return {pump_main: device_id1, pump_f: device_id2}
#             else:
#                 return {pump_f: device_id1, pump_main: device_id2}
#         return {}
#     # 模拟获取泵震动数据
#     def get_vibration(self):
#         pump_main, pump_f = self.bengdata()  # 获取标准化的泵名称
#         # 键格式与get_status保持一致，去除多余描述
#         return {
#             pump_main: [10,0,0],  # 正常振动范围
#             pump_f: [10,1,1]
#         }
#     # 返回蓄能器压力
#     def get_pressure(self):
#         url = "http://222.134.245.144:17000//chuanganqi/BopPanelModel/"
#         response = requests.get(url)
#         if response.status_code == 200:
#             data = response.json()
#             results = data.get("results", [])
#             latest_result = results[0]
#             # 获取储能器的压力值
#             chu_neng_qi_ya_li = latest_result.get("chu_neng_qi_ya_li")
#             a = int(chu_neng_qi_ya_li)
#         return a
#     # 泵不工作时的震动数据（使用与工作数据相同的格式定义）
#     def get_zhi(self):
#         return [0, 0, 0]  # 定义统一的振动数据格式
#
#     # 检查传动皮带或链条是否断裂（关键修复部分）
#     def Cdd(self):
#         pumps = self.get_status()  # 获取状态字典（键格式："泵名称-类型"）
#         pressure = self.get_pressure()  # 获取压力值
#         vibrations = self.get_vibration()  # 获取振动数据（键格式一致）
#         non_working_vibration = self.get_zhi()  # 不工作时的振动特征
#
#         for pump_name, running in pumps.items():
#             # 检查当前泵是否存在于振动数据中（防御性编程）
#             if pump_name not in vibrations:
#                 print(f"警告：未知泵设备 {pump_name}，跳过检查")
#                 continue
#             current_vibration = vibrations[pump_name]
#             # 逻辑条件拆分，增加括号明确优先级
#             condition1 = running and (pressure > 3000)
#             condition2 = (current_vibration == non_working_vibration)
#             if condition1 or condition2:
#                 print(f"检测到 {pump_name} 的传动皮带或链条断裂")
#                 return  # 检测到故障立即返回
#         print("未检测到传动皮带或链条断裂情况")
#     # 灯的调用路径
#     def get_data_from_api(self):
#         api_url=self.url + "BopPanelModel/"
#         try:
#             # 获取restapi路径
#             response = requests.get(api_url)
#             response.raise_for_status()  # 如果状态码不是200，引发异常
#             return response.json()
#         except requests.RequestException as e:
#             print(f"获取数据失败: {e}")
#             return None
#     # 压力开关
#     def yalioff(self):
#         data = self.get_data_from_api()
#         # 获取数据
#         results = data.get("results", [])
#         latest_result = results[0]
#         # 从获取的数据中提取储能器压力
#         a = latest_result.get("chu_neng_qi_ya_li")
#         accumulator_pressure = int(a)
#         deng1 = latest_result.get("dian_beng_1")
#         deng2 = latest_result.get("dian_beng_2")
#         # 从获取的数据中提取1#泵的状态)
#         pump1_status = deng1.get("deng")
#         # 从获取的数据中提取2#泵的状态
#         pump2_status = deng2.get("deng")
#         a, b = self.bengdata()
#         print("储能器压力值:", accumulator_pressure, f"{a}的灯:", pump1_status, f"{b}的灯:", pump2_status)
#         # 判断主泵压力开关：当储能器压力小于等于2700，且主泵状态为不亮（False）时
#         if accumulator_pressure <= 2700 and not pump1_status:
#             print("主泵压力开关损坏或调校不准")
#         # 判断副泵压力开关：当储能器压力小于等于2550，且副泵状态为不亮（False）时
#         elif accumulator_pressure <= 2550 and not pump2_status:
#             print("副泵压力开关损坏或调校不准")
#         # 判断主副泵同时亮起情况：当储能器压力大于等于3000，且主泵或副泵状态为亮（True）时
#         elif accumulator_pressure >= 3000 and (pump1_status or pump2_status):
#             print("存在泵压力开关损坏或调校不准")
#         else:
#             print("压力开关状态正常")
#     # 高压过滤器堵塞检测
#     def get_data(self):
#         # 这里简单模拟返回数据，实际应替换为真实获取逻辑
#         data = self.get_data_from_api()
#         # 获取数据
#         results = data.get("results", [])
#         latest_result = results[0]
#         # 从获取的数据中提取储能器压力
#         a = latest_result.get("chu_neng_qi_ya_li")
#         accumulator_pressure = int(a)
#         deng1 = latest_result.get("dian_beng_1")
#         deng2 = latest_result.get("dian_beng_2")
#         # 从获取的数据中提取1#泵的状态)
#         pump1_status = deng1.get("deng")
#         # 从获取的数据中提取2#泵的状态
#         pump2_status = deng2.get("deng")
#         a, b = self.bengdata()
#         print("储能器压力值:", accumulator_pressure, f"{a}的灯:", pump1_status, f"{b}的灯:", pump2_status)
#         data = {
#             "accumulator_pressure": accumulator_pressure,  # 储能器压力，单位假设为psi
#             "filter_outlet_pressure": 2800,  # 高压过滤器入口端压力，单位假设为psi
#             "pump1_status": pump1_status,  # 1#泵运行状态，True表示运行，False表示停止
#             "pump2_status": pump2_status  # 2#泵运行状态，True表示运行，False表示停止
#         }
#         return data
#
#     # 假设的单泵压差阈值和双泵压差阈值，需根据实际设定值填写
#     # 判断高压过滤器堵塞情况
#     def check_filter_blockage(self):
#         data = self.get_data()
#         accumulator_pressure = data["accumulator_pressure"]
#         filter_outlet_pressure = data["filter_outlet_pressure"]
#         pump1_status = data["pump1_status"]
#         pump2_status = data["pump2_status"]
#
#         # 判断单泵运行情况
#         if (pump1_status ^ pump2_status) and (accumulator_pressure - filter_outlet_pressure > self.single_pump_threshold):
#             print("高压过滤器堵塞（单泵运行时）")
#         # 判断双泵运行情况
#         elif pump1_status and pump2_status and (accumulator_pressure - filter_outlet_pressure > self.double_pump_threshold):
#             print("高压过滤器堵塞（双泵运行时）")
#         else:
#             print("高压过滤器未堵塞")
#     # 泵凡尔泄漏值调用
#     def get_data2(self):
#         # 这里简单模拟返回数据，实际应替换为真实获取逻辑
#         data = self.get_data_from_api()
#         # 获取数据
#         results = data.get("results", [])
#         latest_result = results[0]
#         # 从获取的数据中提取储能器压力
#         a = latest_result.get("chu_neng_qi_ya_li")
#         # 获取出来是字符串格式把他变成int类型
#         accumulator_pressure = int(a)
#         deng1 = latest_result.get("dian_beng_1")
#         deng2 = latest_result.get("dian_beng_2")
#         # 从获取的数据中提取1#泵的状态)
#         pump1_status = deng1.get("deng")
#         # 从获取的数据中提取2#泵的状态
#         pump2_status = deng2.get("deng")
#         print("储能器压力值:", accumulator_pressure, "1号泵的灯:", pump1_status, "2号泵的灯:", pump2_status)
#         data = {
#             "pump1_status": pump1_status,  # 1#泵运行状态，True表示运行，False表示停止
#             "pump2_status": pump2_status,  # 2#泵运行状态，True表示运行，False表示停止
#             "accumulator_pressure": accumulator_pressure,  # 储能器压力，单位假设为psi
#             "pump1_flow": 10,  # 1#泵流量，单位假设为合适流量单位
#             "pump2_flow": 0,  # 2#泵流量，单位假设为合适流量单位
#             "normal_flow_2800": 15,  # 单泵2800psi下正常流量值
#             "normal2_flow_2800": 8,  # 双泵2800psi下正常流量值
#             "normal_flow_2600": 12  # 双泵2600psi下正常流量值
#         }
#         return data
#     # 主泵泵凡尔泄漏处理
#     def check_pump_valve_leakage(self):
#         data = self.get_data2()
#         pump1_status = data["pump1_status"]
#         pump2_status = data["pump2_status"]
#         accumulator_pressure = data["accumulator_pressure"]
#         pump1_flow = data["pump1_flow"]
#         pump2_flow = data["pump2_flow"]
#         normal_flow_2800 = data["normal_flow_2800"]
#         normal2_flow_2800 = data["normal2_flow_2800"]
#         normal_flow_2600 = data["normal_flow_2600"]
#         # 判断主泵
#         if accumulator_pressure >= 2800 and pump1_status and not pump2_status:
#             if pump1_flow < normal_flow_2800:
#                 print("主泵泵凡尔泄漏")
#         #  判断主泵和副泵
#         elif accumulator_pressure >= 2600 and pump1_status and pump2_status:
#             if pump1_flow < normal2_flow_2800:
#                 print("主泵泵凡尔泄漏")
#             if pump2_flow < normal_flow_2600:
#                 print("副泵泵凡尔泄漏")
#         else:
#             print("未检测到泵凡尔泄漏")
#     # 缓冲装置的振幅区间
#     def get_gong_zuo(self):
#         return -5, 5
#     # 缓冲装置数据
#     def huanchongdata(self):
#         pump_main, pump_f = self.bengdata()  # 获取标准化的泵名称
#         # 键格式与get_status保持一致，去除多余描述
#         return {
#             "主泵": [5,0,0],  # 正常振动范围
#             "副泵": [10,1,1]
#         }
#     # 泵组-排出端缓冲装置损坏、电机固定松动、泵动力端损坏
#     def huanchong(self):
#         # 工作时的震动数据
#         vibrations = self.huanchongdata()
#         # 不工作时的震动数据
#         non_working_vibration1, non_working_vibration2 = self.get_gong_zuo()
#         flag1 = False
#         flag2 = False
#         for i in vibrations["主泵"]:
#             if i > non_working_vibration2 or i < non_working_vibration1:
#                 flag1 = True
#         if flag1:
#             print("1号泵排出端缓冲装置损坏、电机固定松动、泵动力端损坏。")
#
#         for i in vibrations["副泵"]:
#             if i > non_working_vibration2 or i < non_working_vibration1:
#                 flag2 = True
#         if flag2:
#             print("2号泵排出端缓冲装置损坏、电机固定松动、泵动力端损坏。")
#
#     # 管汇 - 管汇、万能压力调压阀调压不稳
#     def guanhui(self):
#         url = "http://222.134.245.144:17000//chuanganqi/BopPanelModel/"
#         # 读取路径里面的数据
#         response = requests.get(url)
#         if response.status_code == 200:
#             # 解析数据
#             data = response.json()
#             results = data.get("results", [])
#             wan_neng_ya_li = results[0].get("wan_neng_ya_li")
#             guan_hui_ya_li = results[0].get("guan_hui_ya_li")
#             zhu_liu_liang1 = results[0].get("liu_liang_ji")
#             zhu_liu_liang2 = results[1].get("liu_liang_ji")
#             bypass1 = results[0].get("pang_tong").get("kai_deng")
#             bypass2 = results[1].get("pang_tong").get("kai_deng")
#             if zhu_liu_liang1 == zhu_liu_liang2 and (float(wan_neng_ya_li) > 1500 or float(wan_neng_ya_li) < 1200):
#                 print("万能压力调压不稳")
#             if zhu_liu_liang1 == zhu_liu_liang2 and (
#                     float(guan_hui_ya_li) > 1700 or float(guan_hui_ya_li) < 1200) and bypass1 == bypass2:
#                 print("管汇压力调压不稳")
#
#     # 面板-（换向阀）指示灯损坏
#     def MianB_huanxiang_fa(self):
#         data = {
#             "results": [
#                 {
#                     "id": 1,
#                     "liu_liang_ji": "27.3625",
#                     "wan_neng_ya_li": "27.74375",
#                     "guan_hui_ya_li": "3000",
#                     "chu_neng_qi_ya_li": "3000",
#                     "zuan_ji_qi_ya": "3000",
#                     "pang_tong": {
#                         "hong_yali": False,
#                         "hong_deng": True,
#                         "lv_yali": True,
#                         "lv_deng": True
#                     },
#                     "wan_neng": {
#                         "hong_yali": False,
#                         "hong_deng": True,
#                         "lv_yali": True,
#                         "lv_deng": True
#                     },
#                     "dian_beng_1": {
#                         "deng": True,
#                     },
#                     "dian_beng_2": {
#                         "deng": True,
#                     },
#                     "shang_ya_jing": {
#                         "hong_yali": True,
#                         "hong_deng": True,
#                         "lv_yali": True,
#                         "lv_deng": True
#                     },
#                     "ke_bian_zha_ban": {
#                         "hong_yali": True,
#                         "hong_deng": True,
#                         "lv_yali": True,
#                         "lv_deng": True
#                     },
#                     "shang_zu_liu": {
#                         "hong_yali": True,
#                         "hong_deng": True,
#                         "lv_yali": True,
#                         "lv_deng": True
#                     },
#                     "xia_ya_jing": {
#                         "hong_yali": True,
#                         "hong_deng": True,
#                         "lv_yali": True,
#                         "lv_deng": True
#                     },
#                     "jian_qie_zha_ban": {
#                         "hong_yali": True,
#                         "hong_deng": True,
#                         "lv_yali": True,
#                         "lv_deng": True
#                     },
#                     "xia_zu_liu": {
#                         "hong_yali": True,
#                         "hong_deng": False,
#                         "lv_yali": False,
#                         "lv_deng": True
#                     },
#                     "bei_yong_fa": {
#                         "hong_yali": True,
#                         "hong_deng": True,
#                         "lv_yali": True,
#                         "lv_deng": True
#                     },
#                     "shang_zha_ban": {
#                         "hong_yali": True,
#                         "hong_deng": True,
#                         "lv_yali": True,
#                         "lv_deng": True
#                     },
#                     "xia_zha_ban": {
#                         "hong_yali": True,
#                         "hong_deng": True,
#                         "lv_yali": True,
#                         "lv_deng": True
#                     },
#                     "jin_ji_dian_yuan": {
#                         "deng": True,
#                     },
#                     "div_tong_xin": {
#                         "deng": True,
#                     },
#                     "HPU_tong_xin": {
#                         "deng": True,
#                     },
#                     "bao_jing": {
#                         "deng": True,
#                     },
#                     "lei_ji_power_low": {
#                         "deng": True,
#                     },
#                     "ye_wei_low": {
#                         "deng": True,
#                     },
#                     "zuan_ji_qi_ya_low": {
#                         "deng": True,
#                     },
#                     "beng_ya_li_low": {
#                         "deng": True,
#                     },
#                     "updated": "2025-02-14T10:50:34.521938",
#                     "created": "2025-02-14T10:50:34.521938"
#                 }
#             ]
#         }
#
#         functions = [
#             {
#                 "name": "pang_tong",
#                 "pressure_signals": ["hong_yali", "lv_yali"],
#                 "indicator_signals": ["hong_deng", "lv_deng"]
#             },
#             {
#                 "name": "shang_ya_jing",
#                 "pressure_signals": ["hong_yali", "lv_yali"],
#                 "indicator_signals": ["hong_deng", "lv_deng"]
#             },
#             {
#                 "name": "ke_bian_zha_ban",
#                 "pressure_signals": ["hong_yali", "lv_yali"],
#                 "indicator_signals": ["hong_deng", "lv_deng"]
#             },
#             {
#                 "name": "shang_ya_jing",
#                 "pressure_signals": ["hong_yali", "lv_yali"],
#                 "indicator_signals": ["hong_deng", "lv_deng"]
#             },
#             {
#                 "name": "shang_zu_liu",
#                 "pressure_signals": ["hong_yali", "lv_yali"],
#                 "indicator_signals": ["hong_deng", "lv_deng"]
#             },
#             {
#                 "name": "xia_ya_jing",
#                 "pressure_signals": ["hong_yali", "lv_yali"],
#                 "indicator_signals": ["hong_deng", "lv_deng"]
#             },
#             {
#                 "name": "jian_qie_zha_ban",
#                 "pressure_signals": ["hong_yali", "lv_yali"],
#                 "indicator_signals": ["hong_deng", "lv_deng"]
#             },
#             {
#                 "name": "xia_zu_liu",
#                 "pressure_signals": ["hong_yali", "lv_yali"],
#                 "indicator_signals": ["hong_deng", "lv_deng"]
#             },
#             {
#                 "name": "shang_zha_ban",
#                 "pressure_signals": ["hong_yali", "lv_yali"],
#                 "indicator_signals": ["hong_deng", "lv_deng"]
#             },
#             {
#                 "name": "wan_neng",
#                 "pressure_signals": ["hong_yali", "lv_yali"],
#                 "indicator_signals": ["hong_deng", "lv_deng"]
#             },
#             {
#                 "name": "xia_zha_ban",
#                 "pressure_signals": ["hong_yali", "lv_yali"],
#                 "indicator_signals": ["hong_deng", "lv_deng"]
#             },
#
#         ]
#
#         # 采集主流量计流量
#         main_flow_rate = float(data["results"][0]["liu_liang_ji"])
#         # 模拟上一次采集的主流量计流量，这里假设初始为 0
#         last_main_flow_rate = 0
#
#         # 判断指示灯是否损坏
#         for func in functions:
#             func_data = data["results"][0][func["name"]]
#             for i in range(len(func["pressure_signals"])):
#                 pressure_signal = func_data[func["pressure_signals"][i]]
#                 indicator_signal = func_data[func["indicator_signals"][i]]
#                 flow_increased = main_flow_rate > last_main_flow_rate
#
#                 if pressure_signal != indicator_signal and flow_increased:
#                     print(f"{func['name']} 的 {func['indicator_signals'][i]} 指示灯损坏")
#     # 管汇-电磁阀损坏堵塞、驱动气缸卡阻
#     def check_valves_and_cylinders(self):
#         # 获取主流量计当前流量
#         current_flow = float(self.data.get("liu_liang_ji", 0))
#         # 这里假设功能输出前的流量值是已知的，实际应用中需要根据实际情况获取
#         previous_flow = 27.3  # 示例值
#         # 计算流量差值
#         flow_difference = abs(current_flow - previous_flow)
#         # 设置流量差值的阈值，示例为0.1
#         threshold = 0.1
#         # 获取所有需要检查的压力字段
#         pressure_keys = [
#             "pang_tong", "wan_neng", "shang_ya_jing", "ke_bian_zha_ban",
#             "shang_zu_liu", "xia_ya_jing", "jian_qie_zha_ban", "xia_zu_liu",
#             "bei_yong_fa", "shang_zha_ban", "xia_zha_ban"
#         ]
#         satisfied_keys = []
#         unsatisfied_keys = []
#         # 判断每个指定字段的红灯和绿灯压力值是否都为True
#         for key in pressure_keys:
#             sub_data = self.data.get(key)
#             print(sub_data)
#             if sub_data.get("hong_yali") and sub_data.get("lv_yali"):
#                 satisfied_keys.append(key)
#             else:
#                 unsatisfied_keys.append(key)
#         # 判断是否满足条件并输出结果带字段名
#         if flow_difference < threshold:
#             result_message = f"电磁阀损坏堵塞、驱动气缸卡阻：{', '.join(satisfied_keys)}"
#             if unsatisfied_keys:
#                 result_message += f"；以下字段不满足压力条件：{', '.join(unsatisfied_keys)}"
#             print(result_message)
#     # qi
#     import requests
#     # 清洁剂是都超标
#     def Youqj(self):
#             url = self.url + 'QjdDeviceModel/'
#             response = requests.get(url)
#             # 检查请求是否成功
#             if response.status_code == 200:
#                 # 解析数据
#                 data = response.json()
#                 # 获取数据
#                 results = data.get("results", [])
#                 if not results:
#                     print("后端没有数据")
#                     return
#                 latest_result = results[-1]
#                 # 假设清洁度数据在返回结果中的键名为"cleanliness_value"
#                 # 实际需根据真实数据结构调整
#                 cleanliness_value = latest_result.get("data")
#                 if cleanliness_value == {}:
#                     print("未获取到有效清洁度数据")
#                     return
#                 # 设置清洁度标准值，这里假设为50，实际需根据业务需求调整
#                 standard_value = 1
#                 if cleanliness_value > standard_value:
#                     print(f"清洁度设定值判断超标，当前值为{cleanliness_value}，高于标准值{standard_value}")
#                 else:
#                     print(f"清洁度未超标，当前值为{cleanliness_value}")
#             else:
#                 print(response.status_code)
#
# data = {
#         "id": 1,
#         "liu_liang_ji": "27.3625",
#         "wan_neng_ya_li": "27.74375",
#         "guan_hui_ya_li": "3000",
#         "chu_neng_qi_ya_li": "3000",
#         "zuan_ji_qi_ya": "3000",
#         "pang_tong": {
#             "hong_yali": True,
#             "hong_deng": True,
#             "lv_yali": True,
#             "lv_deng": True
#         },
#         "wan_neng": {
#             "hong_yali": True,
#             "hong_deng": True,
#             "lv_yali": True,
#             "lv_deng": True
#         },
#         "dian_beng_1": {
#             "deng": True,
#         },
#         "dian_beng_2": {
#             "deng": True,
#         },
#         "shang_ya_jing": {
#             "hong_yali": True,
#             "hong_deng": True,
#             "lv_yali": True,
#             "lv_deng": True
#         },
#         "ke_bian_zha_ban": {
#             "hong_yali": True,
#             "hong_deng": True,
#             "lv_yali": True,
#             "lv_deng": True
#         },
#         "shang_zu_liu": {
#             "hong_yali": True,
#             "hong_deng": True,
#             "lv_yali": True,
#             "lv_deng": True
#         },
#         "xia_ya_jing": {
#             "hong_yali": True,
#             "hong_deng": True,
#             "lv_yali": True,
#             "lv_deng": True
#         },
#         "jian_qie_zha_ban": {
#             "hong_yali": True,
#             "hong_deng": True,
#             "lv_yali": True,
#             "lv_deng": True
#         },
#         "xia_zu_liu": {
#             "hong_yali": True,
#             "hong_deng": True,
#             "lv_yali": True,
#             "lv_deng": True
#         },
#         "bei_yong_fa": {
#             "hong_yali": True,
#             "hong_deng": True,
#             "lv_yali": True,
#             "lv_deng": True
#         },
#         "shang_zha_ban": {
#             "hong_yali": True,
#             "hong_deng": True,
#             "lv_yali": True,
#             "lv_deng": True
#         },
#         "xia_zha_ban": {
#             "hong_yali": True,
#             "hong_deng": True,
#             "lv_yali": True,
#             "lv_deng": True
#         },
#         "jin_ji_dian_yuan": {
#             "deng": True,
#         },
#         "div_tong_xin": {
#             "deng": True,
#         },
#         "HPU_tong_xin": {
#             "deng": True,
#         },
#         "bao_jing": {
#             "deng": True,
#         },
#         "lei_ji_power_low": {
#             "deng": True,
#         },
#         "ye_wei_low": {
#             "deng": True,
#         },
#         "zuan_ji_qi_ya_low": {
#             "deng": True,
#         },
#         "beng_ya_li_low": {
#             "deng": True,
#         },
#         "updated": "2025-02-14T10:50:34.521938",
#         "created": "2025-02-14T10:50:34.521938"
# }
#     # 示例用法：
# # 每隔五秒就会执行一
# test = Test(data)
# # while True:
# test.Qip1()
# test.Qip2()
# test.XnqX1()
# test.XnqX2()
# test.Cdd()
# test.yalioff()
# # 高压过滤器堵塞情况
# test.check_filter_blockage()
# test.bengdata()
# test.huanchong()
# test.guanhui()
# test.MianB_huanxiang_fa()
# test.check_valves_and_cylinders()
# test.Youqj()
#     # time.sleep(5)
#
# # 监测30秒流量数据
# total_time = 30# 一共检测30次
# interval = 1  # 每隔1秒进行一次监测
# for i in range(total_time // interval):
#     print(f"第 {i + 1} 次监测:")
#     test.check_pump_valve_leakage()
#     time.sleep(interval)